package com.jxsd.edu.cn.struts2.serviceImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.PubMsgDao;
import com.jxsd.edu.cn.struts2.dao.PublishGoodAttributeDao;
import com.jxsd.edu.cn.struts2.daoImpl.PubMsgDaoImpl;
import com.jxsd.edu.cn.struts2.daoImpl.PublishGoodAttributeDaoImpl;
import com.jxsd.edu.cn.struts2.models.PubMsgview;
import com.jxsd.edu.cn.struts2.models.PublishGoodAttribute;
import com.jxsd.edu.cn.struts2.services.PubMsgService;
import com.jxsd.edu.cn.tools.Page;
import com.jxsd.edu.cn.tools.PageBean;

public class PubMsgServiceImpl implements PubMsgService
{
    private    PubMsgDao  dao=new  PubMsgDaoImpl();
    private    PublishGoodAttributeDao  attriDao=new  PublishGoodAttributeDaoImpl();
	@Override
	public PubMsgview getPubMsg(String publishId) {
		//设置物品记录的属性信息
		PubMsgview  msg=dao.getPubMsg(publishId);
		
		List<PublishGoodAttribute>  list=attriDao.getAttributes(publishId);
		msg.setAttributes(list);
		
		System.out.println("******************PubMsgServiceImpl*******************");
		for(PublishGoodAttribute  attr:list)
		{
			System.out.println(attr.getAttributeName()+":"+attr.getAttributeValue());
		}
		
		return msg;
	}

	@Override
	public   Page<PubMsgview>   getSmallPubMsgTitles(String  cityName,String  smallId,PageBean<PubMsgview>  pagebean) {
		Page<PubMsgview>   page=null;
		page=dao.getPagePubMsgTitle(cityName,"smallId", smallId, pagebean);
		
		for(PubMsgview  msg:page.getList())
		{
			List<PublishGoodAttribute>  attributes=attriDao.getHotAttributes(Integer.toString(msg.getPublishID()));
			msg.setAttributes(attributes);
		}
		return   page;
	}

	@Override
	public   Page<PubMsgview>   getCataPubMsgTitles(String  cityName,String  catagoryId,PageBean<PubMsgview>  pagebean)
	{
		Page<PubMsgview>   page=null;
		page=dao.getPagePubMsgTitle(cityName,"catagoryId", catagoryId, pagebean);
		
		for(PubMsgview  msg:page.getList())
		{
			List<PublishGoodAttribute>  attributes=attriDao.getHotAttributes(Integer.toString(msg.getPublishID()));
			msg.setAttributes(attributes);
		}
		return   page;
	}

	@Override
	public   Page<PubMsgview>   getPersonPubMsgs(String  userId,PageBean<PubMsgview>  pagebean){
		return dao.getPagePubMsgTitle("Author", userId, pagebean);
	}

	@Override
	public List<PubMsgview> getPubMsgs(String smallId, String cityName) {
		return dao.getPubMsgs(smallId, cityName);
	}

	@Override
	public List<PubMsgview> getLabelPubMsgs(String[] smallNames, String cityName,
			String univerName) {
		return dao.getLabelPubMsgs(smallNames, cityName, univerName);
	}

	@Override
	public Page<PubMsgview> recommendPubMsg(String nickName) 
	{
		return dao.recommendPubMsg(nickName);
	}

	@Override
	public void pubMsg(PubMsgview msg) {
		//将物品记录基本信息存到数据库
		
		System.out.println("**********************pubMsg:publishID***********************");
		System.out.println("publishId"+msg.getPublishID());
		System.out.println("**********************pubMsg:publishID***********************");
		dao.pubMsg(msg);
		//将物品属性信息存到数据库
		attriDao.updatePubMsgAttris(Integer.toString(msg.getPublishID()), msg.getAttributes());
	}

	@Override
	public void deletePubMsg(String publishId) 
	{
		attriDao.deletePubMsgAttri(publishId);
		dao.deletePubMsg(publishId);
	}

	@Override
	public void updatePubMsg(PubMsgview msg) 
	{
		dao.updatePubMsg(msg);
		//更新这条记录的属性描述
		attriDao.updateGoodAttri(Integer.toString(msg.getPublishID()), msg.getAttributes());
	}

	@Override
	public List<PubMsgview> queryNewlyMsgs(String cityName)
	{
		return dao.queryNewlyMsgs(cityName);
	}

}
